﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System;

namespace NSQL.Expressions
{
    public interface IConstantNumericExpression : INumericExpression
    {
        /// <summary>
        /// Get the sign of the number.
        /// </summary>
        int Sign { get; }
        
        bool IsZero { get; }

        void MakeOpposite();

    }
    public class NumericExpression : ConstantExpression, IConstantNumericExpression, IConstantExpression<double>
    {
        public double Value { get; set; }

        public override object ValueOf() => Value;

        private NumericExpression(double value) => Value = value;
        public int Sign => Math.Sign(Value);
        public bool IsZero => !(Math.Abs(Value) > 0);
        public void MakeOpposite() => Value *= -1;
        public static implicit operator NumericExpression(double val) => new NumericExpression(val);
        public static implicit operator NumericExpression(float val) => new NumericExpression(val);
        protected override IExpression DeepCopy()
        {
            return new NumericExpression(Value)
            {
                Tag = Tag
            };
        }
    }
}